#include "DictionaryProducer.hpp"
#include "Configuration.hpp"
#include "StringSplit.hpp"
#include "SplitTool.hpp"
#include "Debug.hpp"


int main()
{
    using namespace se;

    DictionaryProducer dict(CONFIGURATION("EnglishStopWord", std::string),CONFIGURATION("EnglishYuLiao", std::string));
    dict.getFiles();
    dict.buildEnDictionary();
    DEBUG_PRINT("create dictionary english success.");

    SplitTool *tm =new SplitToolCppJieba();
    DictionaryProducer dict2(CONFIGURATION("ChineseStopWord", std::string),CONFIGURATION("ChineseYuLiao", std::string), tm);
    dict2.getFiles();
    dict2.buildCnDictionary();
    DEBUG_PRINT("create dictionary chinese success.");

    // 将中英文字典合并
    auto englishDictionary = dict.getDictionary();
    auto chineseDictionary = dict2.getDictionary();
    englishDictionary.insert(englishDictionary.end(), chineseDictionary.begin(), chineseDictionary.end());

    // 将合并后的字典输出
    std::ofstream dictionaryOutputStream(CONFIGURATION("DictionaryPath", std::string));
    nlohmann::json j(englishDictionary);
    dictionaryOutputStream << j.dump(4);
    dictionaryOutputStream.close();
    DEBUG_PRINT("生成字典文件成功.");

    // 通过字典生成索引文件
    DictionaryProducer::createIndex(CONFIGURATION("DictionaryPath", std::string),
                                    CONFIGURATION("IndexPath", std::string));
    DEBUG_PRINT("生成索引文件成功.");

    return 0;
}
